import {
  Component
} from '@angular/core';
import {
  NavController,
  NavParams
} from 'ionic-angular';

import _ from 'lodash';
import {
  Backend
} from '../../providers/backend';

@Component({
  templateUrl: 'build/pages/tab-events/tab-suveryInfo.html',
})
export class TabsuveryInfo {

  static get parameters() {
    return [
      [NavController],
      [NavParams],
      [Backend]
    ];
  }

  constructor(nav, navParams, backend) {
    this.nav = nav;
    this.backend = backend;
    this.navParams = navParams;
    this.ques;
    this.name;
    this.email;
    this.company;
    this.name;
    this.email;
    
    this.a;
    this.b;
    this.company;
    this.suvery = {};
    this.abcd = ['A', 'B', 'C', 'D'];
    this.efgh = ['e', 'f', 'g', 'h', 'i', 'g', 'k'];
    this.id = navParams.get('id');
    this.backend.suvery(this.id)
      .then(result => {
        this.suvery = result.result[0];
        console.log(this.suvery);
        this.ques = _.values(this.suvery.ques);
        console.log(this.ques.length);

      });


  }
  submit() {
    this.data = {};
    for (let i = 0; i < this.ques.length; i++) {
      if (this.ques[i].type == 1) {
        
        this.data[this.ques[i].input_name]=this.ques[i].b;
        console.log(this.data);
      } else if (this.ques[i].type == 3) {
        this.data[this.ques[i].input_name] = this.ques[i].a;
        console.log(this.data);
        
      } else if (this.ques[i].type == 2) {
        this.duoxuan = '';
        for (let j = 0; j <= this.ques.length; j++) {
          for(let k=0;k<=this.efgh.length;k++){
            if(this.efgh[k]==this.ques[i].con.split('/')[j]){
              this.duoxuan=this.duoxuan + this.efgh[k]+'/';
            }
          }
         
          
        }
        console.log(this.duoxuan);
         this.data[this.ques[i].input_name]=this.duoxuan;
        
      }

    }
    this.data.name = this.name;
    this.data.email = this.email;
    this.data.company =this.company;
    console.log(this.data);
    this.backend.suveryInfo(this.data)
      .then(result => {

        console.log(result);
this.nav.pop();

      });
  }
  quzhi(items,qIndex){
    if(this.efgh[qIndex]==items){
      this.efgh[qIndex]=!items;
    }else{this.efgh[qIndex]=items;}
    
  }

}